<?php
class item_bypassflood extends template_item
{
	var $default_name = "Bypass Flood Control";
	var $default_description = "Bypass the flood control!";
	
	var $allow_multiple = 1;
	
	var $item_config = array();
	
	function admin_save()
	{
		if($this->ipsclass->DB->field_exists("bypass_flood", "members"))
		{
			$this->ipsclass->DB->sql_change_field("members","bypass_flood","bypass_flood","tinyint NOT NULL","'0'");
		}
		else
		{
			$this->ipsclass->DB->sql_add_field("members","bypass_flood","tinyint NOT NULL","'0'");
		}
	}
	
	function admin_remove()
	{
		if(count($this->ipsclass->market_class->item_by_folder[$this->item['filename']]) == 1)
		{
			$this->ipsclass->DB->sql_drop_field("members","bypass_flood");
		}
	}
	
	function admin_view_file_edits()
	{
		$edits = "";
		
		$edits .= $this->ipsclass->adskin->start_table("Files to edit");
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"/sources/action_public/post.php",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();

		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		$this->ipsclass->adskin->td_header[] = array( "{none}"  , "" );
		
		$edits .= $this->ipsclass->adskin->start_table("/sources/action_public/post.php");
		$edits .= $this->ipsclass->adskin->add_td_basic('About line 194', 'left', 'tablesubheader');
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Find",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>					if (\$this->ipsclass->member['g_avoid_flood'] != 1)\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Under the functions",
																"topics_get_posts( \$a )",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"Add before",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>					\$mem = \$this->ipsclass->DB->build_and_exec_query(array('select'=>'bypass_flood','from'=>'members','where'=>\"id=\".\$this->ipsclass->member['id']));\n					\$this->ipsclass->member['g_avoid_flood'] = (\$this->ipsclass->member['g_avoid_flood'] or \$mem['bypass_flood']);\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->add_td_row(array(
																"It will look like",
																"<textarea rows='5' cols='50' class='multitext' style='width:98%'>					\$mem = \$this->ipsclass->DB->build_and_exec_query(array('select'=>'bypass_flood','from'=>'members','where'=>\"id=\".\$this->ipsclass->member['id']);)\n					\$this->ipsclass->member['g_avoid_flood'] = (\$this->ipsclass->member['g_avoid_flood'] or \$mem['bypass_flood']);\n					if (\$this->ipsclass->member['g_avoid_flood'] != 1)\n</textarea>",
														)	);
		$edits .= $this->ipsclass->adskin->end_table();
		
		return $edits;
	}
	
	function public_use_item($inventory_ids = array()) 
	{
		$this->ipsclass->load_language('lang_market_items');
		
		$this->ipsclass->DB->do_update('members',array(
														'bypass_flood' => 1,
				),"id=".$this->ipsclass->member['id']);
		
		$this->delete_items($inventory_ids);
		
		foreach($inventory_ids as $inv_id)
		{
			$this->_write_log($inv_id, "Triggered bypass flood control");
		}
		
		$this->ipsclass->market_class->redirect('bypass_flood_control');
	}
}
?>